
package com.xm9m.ibczy.mytest.alimama.mobile.demo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.alimama.mobile.sdk.MmuSDK;
import com.alimama.mobile.sdk.config.LoopImageConfig;
import com.alimama.mobile.sdk.config.LoopImageConfig.onPageChangedListener;
import com.alimama.mobile.sdk.config.LoopImageController;
import com.alimama.mobile.sdk.config.LoopImageProperties;
import com.alimama.mobile.sdk.config.MMPromoter;
import com.alimama.mobile.sdk.config.MmuSDKFactory;
import com.xm9m.ibczy.mytest.R;

public class LoopImageActivity extends BaseActivity {
    private LoopImageProperties properties;
    private LoopImageController mController;
	private MmuSDK mmuSDK;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loop_image);
        setTitle("轮播大图");

        ViewGroup nat = (ViewGroup) findViewById(R.id.loop);
        String slotId = "54361";//注意：该广告位只做测试使用，请勿集成到发布版app中
        setupAlimama(nat, slotId);

    }

    private void setupAlimama(ViewGroup nat, String slotId) {
        mmuSDK = MmuSDKFactory.getMmuSDK();
        mmuSDK.accountServiceInit(this);
        mmuSDK.init(getApplication());//初始化SDK,该方法必须保证在集成代码前调用，可移到程序入口处调用
        properties = new LoopImageProperties(slotId, nat);
        LoopImageConfig config = new LoopImageConfig();
        config.setPageChangedListener(new onPageChangedListener() {
            @Override
            public void onPageChanged(int arg0, MMPromoter arg1, View parent) {
                String title = arg1.getTitle();
                if(mController != null) {
                    mController.setTitle((ViewGroup) parent, title);
                }
            }
        });
        properties.setConfig(config);
        mmuSDK.attach(properties);
        mController = (LoopImageController) properties.getMmuController();
    }
    
    @Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (!mmuSDK.accountServiceHandleResult(requestCode, resultCode, data,this)) {
			super.onActivityResult(requestCode, resultCode, data);
		}
	}
}
